#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
string a[1001];int n;
string b[1001];int ak=0;int bk=0;
bool chazha(string cc,int p){
	int shu=cc.size();int aki=0;
	if(p==2){
		for(int i=1;i<=ak;i++){
			for(int j=0;j<shu;j++){
				if(cc[j]==a[i][j])
				{
					aki++;
					if(aki==shu)
					cout<<i<<endl;
				}
			}
		}
	}
	else{
		int bbb=0;
		for(int i=1;i<=ak;i++){
			for(int j=0;j<shu;j++){
				if(cc[j]==a[i][j]){
					aki++;
					if(aki==shu&&i!=ak){
						cout<<"FAIL"<<endl;
						bbb=1;
					}
					
				}
			}
		}
		if(!bbb) cout<<"OK"<<endl;
	}
}
void pd(int xx,int p){
	int x;int sum=0;bool y=0;int k=0;int bb=0;
	while(cin>>x&&!y){
		sum++;
		k+=int(x-'0')*sum;
		if(k>255&&!y){
			cout<<"1ERR"<<endl;
			break;
		}
		if(sum==1&&x=='0'){
			cout<<"2ERR"<<endl;
			break;
		}
	//	if(x>'9'||x<'0'){			cout<<"3ERR"<<endl;			break;		}
		if(x=='.') {
			sum=0;k=0;bb++;
		}
		if(x==':') y=1;
		if(p==1)
		a[xx]+=x;
		if(p==2)
		b[xx]+=x;
	}
	if(bb!=3) cout<<"4ERR";
	chazha(a[xx],p);
}
int main()
{
	freopen("network.in","r",stdin);	freopen("network.out","w",stdout);
	cin>>n;
for(int i=1;i<=n;i++){
	string k;
	cin>>k;
	if(k=="Server"){
			ak++;
			pd(ak,1);	
		}
		else{
			bk++;
			pd(bk,2);
		}
		
	}
	
	fclose(stdin); fclose(stdout);
}
